//<![CDATA[
jQuery(document).ready(function($){
	var stepInterval = 4000;
    var initialDelay = 2000;
    var fadeTime = 1000;
    var carouselID;
    var i=1;
    function myAfterCall() {
    	$('.carouselProgress').width(0);
    }

    function myBeforeCall() {
    	$('#sliderTimer-header .active').removeClass('active');
    	startProgress();
    	carouselID = $(this).attr('id').replace('mas-', '');
    	startProgress(carouselID);
    	$('#mas-head-'+carouselID).addClass('active');
    }
    function startProgress(carouselID){
    	parentWidth = $('#mas-head-'+carouselID).width();
        $('#mas-head-'+carouselID+' .carouselProgress').animate({width: parentWidth+"px"}, (stepInterval), 'linear');
    }
    $('.sliderTimer-item-header').live('click', function(a){
    	var clicked = $(this);
    	$('.sliderTimer-item-header').each(function(e){
    		console.log(clicked.attr('id'));
    		console.log($(this).attr('id'));
    		if(clicked.attr('id')!=$(this).attr('id')){
    			$(this).children('.carouselProgress').stop();
    		}
    	});
    });
    //$('.sliderTimer-item').hover(function(){}, function(){});

	$('#sliderTimer').cycle({
		delay: initialDelay,
 		timeout: stepInterval,
		speed: fadeTime,
		after: myAfterCall,
		before: myBeforeCall,
		pager: '#sliderTimer-header',
		pause: true,
		pagerAnchorBuilder: function(idx, slide) {

			carouselID = slide.id.replace('mas-', '');
			carouselTitle = $(slide).attr('ref');
			if(i==1) {
				myClass="active"

			} else {
				myClass="";
			}
			i++;
			return '<li> \
            <a href="#" class="sliderTimer-item-header '+myClass+'" id="mas-head-'+carouselID+'"> \
            <div class="carouselProgress"></div> \
             <span class="carouselHeaderContent">'+carouselTitle+'</span> \
                <span class="carouselHeaderDecorator"></span> \
         </a> \
      </li>';
		}
	});
	//$('#sliderTimer-header:first-child').addClass('active');
	parentWidth = $('#sliderTimer-header .active .carouselProgress').width();
	$('#sliderTimer-header .active .carouselProgress').animate({width: parentWidth+"px"}, (stepInterval), 'linear');
});
 //]]>